/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2013 All Rights Reserved.
 */
package com.h2o3.sample.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.h2o3.carmack.message.Message;
import com.h2o3.carmack.message.annotation.Handler;
import com.h2o3.carmack.message.annotation.HandlerMapping;
import com.h2o3.carmack.session.Session;
import com.h2o3.sample.model.User;
import com.h2o3.sample.service.ChatService;
import com.h2o3.sample.service.UserService;

/**
 * @author chensheng
 * @version $Id: ConnectHandler.java, v 0.1 12/6/13 10:39 PM chensheng Exp $
 */
@Handler
public class ConnectHandler {
    private static final Logger logger = LoggerFactory.getLogger(ConnectHandler.class);

    @Autowired
    private UserService         userService;

    @Autowired
    private ChatService         chatService;

    @HandlerMapping("connect")
    public void handle(Session session, Message message) {
        logger.info("这是一个测试，说明有个家伙连上来了！");

        User user = userService.get("3");
        if (user != null) {
            session.put("userName", user.getName());
        } else {
            logger.info("没有找到用户哦");
        }

        chatService.join(session);
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public ChatService getChatService() {
        return chatService;
    }

    public void setChatService(ChatService chatService) {
        this.chatService = chatService;
    }
}
